/*myshell.c*/
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
void parent(int *status){
   wait(status);
}
int split( char **arr, char *str, const char *del)//

{  char *s =NULL;
   int number=0;
  s=strtok(str,del); 
  while(s != NULL){
  *arr++ = s;
  s = strtok(NULL,del);
  number++;  }
  return number;
}
void main(){
char *args[10];
char arg[100];  //
pid_t pid;
int status,num;
while (1)
{
printf("please input command:\n");
memset(args, 0x0, sizeof(args)); //
gets(arg);
if (strcmp("#",arg)==0) break;
num=split(args,arg," ");
pid=fork();
if (pid<0) { printf("fork failed\n"); exit(0);}
else if (pid==0) {
    if (num>0)
        execvp(args[0],args+1);
    else
        execvp(args[0],NULL);
}
else wait(&status);
}
}
